package team.bluepen.order.data.entity;

import space.lingu.light.DataColumn;
import space.lingu.light.DataTable;
import space.lingu.light.PrimaryKey;

import java.util.Objects;

/**
 * 订单
 * @author RollW
 */
@DataTable(tableName = "order_table")
public class Order {
    /**
     * 订单id（订单号）
     */
    @PrimaryKey
    @DataColumn(name = "order_id")
    private long id;

    /**
     * 订单名称
     */
    @DataColumn(name = "order_name")
    private String name;

    /**
     * 订单日期
     */
    @DataColumn(name = "order_date")
    private String date;

    /**
     * 订单数量
     */
    @DataColumn(name = "order_amount")
    private int amount;

    /**
     * 订单是否有效
     */
    @DataColumn(name = "order_valid")
    private boolean valid;

    public Order() {
    }

    public long getId() {
        return id;
    }

    public Order setId(long id) {
        this.id = id;
        return this;
    }

    public String getName() {
        return name;
    }

    public Order setName(String name) {
        this.name = name;
        return this;
    }

    public String getDate() {
        return date;
    }

    public Order setDate(String date) {
        this.date = date;
        return this;
    }

    public int getAmount() {
        return amount;
    }

    public Order setAmount(int amount) {
        this.amount = amount;
        return this;
    }

    public boolean isValid() {
        return valid;
    }

    public Order setValid(boolean valid) {
        this.valid = valid;
        return this;
    }

    public Order setValid(String valid) {
        return setValid(valid.equalsIgnoreCase("Y"));
    }

    @Override
    public String toString() {
        return "Order{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", date='" + date + '\'' +
                ", amount=" + amount +
                ", valid=" + valid +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Order order = (Order) o;
        return id == order.id && amount == order.amount && valid == order.valid && Objects.equals(name, order.name) && Objects.equals(date, order.date);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name, date, amount, valid);
    }
}
